#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <mpi_sys.h>

/*
    usage: ./cpuid 32
*/
#define USE_CPUID

int main(int argc, char**argv)
{
    int fd, cmd;
    SC_S32 ret = 0;
    SC_U32 chipid = 0;
    SC_U64 sn_code = 0;
    
    if(argc < 2)
    {
        printf("Usage:\n");
        printf("    get chipid command: ./cpuid 32\n");
        printf("    get SN: ./cpuid 64\n");
        return 0;
    }
    else
    {
        cmd = atoi(argv[1]);
    }
	/* sc system init */
	SC_MPI_SYS_Init();  
    switch(cmd)
    {
        case 32: 
            printf("Read chipid start...\n\n");
            ret = SC_MPI_SYS_GetChipId(&chipid);
            #ifdef USE_CPUID
            if(ret<0)
            {
                printf("ret value : %#x\n", ret);
                perror("error");
            }
            else
            {
				printf("Get chipid : 0x%08x\n", chipid);
            }
            #else
            printf("Get chipid : 0x%08x\n", chipid);
			#endif
        break;
        case 64:
            printf("Read SN Code start...\n\n");
            ret = SC_MPI_SYS_GetCustomCode(&sn_code);
            #ifdef USE_CPUID
			if(ret<0)
            {
                printf("ret value : %#x\n", ret);
                perror("error");
            }
            else
            {
				printf("Get SN Code: 0x%016x\n", sn_code);
			}
			#else
			printf("Get SN Code: 0x%016x\n", sn_code);
			#endif
        break;
    }
	SC_MPI_SYS_Exit();
    
    return 0;
}
